home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / wasm223.zip / MACRO2.ASM < prev    next >
Assembly Source File  |  1993-05-04  |  6KB  |  234 lines

  1. ;*******************************************;
  2. ; WASM Macro Processor, Debug Info          ;
  3. ; By Eric Tauck                             ;
  4. ;                                           ;
  5. ; Defines:                                  ;
  6. ;                                           ;
  7. ;   MacUnd  return undefined compile symbol ;
  8. ;   MacCur  current state (IP,stack,return) ;
  9. ;   MacStk  read stack values               ;
  10. ;   MacRet  read return values              ;
  11. ;   MacSym  return the symbol of an address ;
  12. ;                                           ;
  13. ; Requires:                                 ;
  14. ;                                           ;
  15. ;   MACRO1.ASM                              ;
  16. ;*******************************************;
  17.  
  18.         jmp     _macro2_end
  19.  
  20. _mac_ssym       DB      7, '(start)'    ;start symbol
  21.  
  22. ;========================================
  23. ; Return undefined symbol.
  24. ;
  25. ; In: AX= place to put symbol.
  26. ;
  27. ; Out: CY= set if not undefined symbol or
  28. ;      symbol table info not preserved
  29. ;      (MacBug = 0).
  30.  
  31. MacUnd  PROC    NEAR
  32.         push    di
  33.         push    si
  34.         push    ds
  35.  
  36.         mov     cx, _mac_undlen ;length of symbol
  37.         mov     di, ax
  38.         mov     si, _mac_undoff ;symbol offset
  39.         or      si, si          ;check if exists
  40.         jz      _mcund1         ;exit if not
  41.         mov     ax, _mac_symseg ;load symbol segment
  42.         or      ax, ax          ;check if preserved
  43.         jz      _mcund1         ;exit if not
  44.         mov     ds, ax
  45.  
  46. ;--- copy symbol
  47.  
  48.         cld
  49.         rep
  50.         movsb                   ;copy symbol
  51.         sub     al, al
  52.         stosb                   ;store NUL
  53.  
  54.         pop     ds
  55.         pop     si
  56.         pop     di
  57.         clc
  58.         ret
  59.  
  60. ;--- symbol not returned
  61.  
  62. _mcund1 pop     ds
  63.         pop     si
  64.         pop     di
  65.         stc
  66.         ret
  67.         ENDP
  68.  
  69. ;========================================
  70. ; Return the current state.
  71. ;
  72. ; Out: AX= current location; BX= number
  73. ;      of items on stack; CX= number of
  74. ;      items on return stack.
  75.  
  76.  
  77. MacCur  PROC    NEAR
  78.         mov     ax, _mac_codsav
  79.         mov     bx, _mac_stksiz
  80.         sub     bx, _mac_stksav
  81.         shr     bx
  82.         mov     cx, _mac_codsiz
  83.         dec     cx
  84.         dec     cx
  85.         sub     cx, _mac_retsav
  86.         shr     cx
  87.         ret
  88.         ENDP
  89.  
  90. ;========================================
  91. ; Copy items from the stack.
  92. ;
  93. ; In: AX= place to store items; CX=
  94. ;     number of items.
  95.  
  96. MacStk  PROC    NEAR
  97.         push    di
  98.         push    si
  99.         push    ds
  100.         mov     di, ax                  ;place to put items
  101.         mov     si, _mac_stksav         ;source offset
  102.         mov     ds, _mac_stkseg         ;source segment
  103.         cld
  104.         rep
  105.         movsw                           ;copy items
  106.         pop     ds
  107.         pop     si
  108.         pop     di
  109.         ret
  110.         ENDP
  111.  
  112. ;========================================
  113. ; Copy items from the return stack.
  114. ;
  115. ; In: AX= place to store items; CX=
  116. ;     number of items.
  117.  
  118. MacRet  PROC    NEAR
  119.         push    di
  120.         push    si
  121.         push    ds
  122.         mov     di, ax                  ;place to put items
  123.         mov     si, _mac_retsav         ;offset
  124.         inc     si
  125.         inc     si                      ;adjust, point to last item
  126.         mov     ds, _mac_codseg         ;source segment
  127.         cld
  128.         rep
  129.         movsw                           ;copy items
  130.         pop     ds
  131.         pop     si
  132.         pop     di
  133.         ret
  134.         ENDP
  135.  
  136. ;========================================
  137. ; Return the last symbol before an
  138. ; address.
  139. ;
  140. ; In: AX= address; BX= place to store
  141. ;     symbol.
  142. ;
  143. ; Out: CY= no symbol returned (out of
  144. ;      range or no symbol table); AX=
  145. ;      byte offset past symbol.
  146.  
  147. MacSym  PROC     NEAR
  148.         push    di
  149.         push    si
  150.         push    bp
  151.         push    ds
  152.  
  153.         cld
  154.         mov     di, bx
  155.         mov     bp, ax
  156.  
  157. ;--- check for special cases
  158.  
  159.         cmp     ax, _mac_codptr         ;check if address out of range
  160.         jae     _mcsym5                 ;exit if so
  161.  
  162.         mov     dx, OFFSET _mcstar      ;beginning address
  163.         cmp     ax, dx                  ;check if address out of range
  164.         jb      _mcsym5
  165.  
  166.         mov     ax, _mac_symseg         ;symbol table segment
  167.         or      ax, ax                  ;check if none
  168.         jz      _mcsym5
  169.  
  170. ;--- loop through symbol table
  171.  
  172.         mov     ds, ax          ;table segment
  173.         sub     si, si          ;start of symbol table
  174.         mov     bx, si
  175.         dec     bx              ;set symbol offset to FFFF
  176.         jmps    _mcsym2
  177.  
  178. _mcsym1 mov     dx, [si]        ;load symbol address
  179.         pop     bx              ;address of symbol string
  180.         inc     si              ;
  181.         inc     si              ;skip value
  182.  
  183. _mcsym2 seg     es
  184.         cmp     si, _mac_symptr ;check if end of table
  185.         je      _mcsym3
  186.  
  187.         push    si
  188.         lodsb                   ;load length of symbol
  189.         sub     ah, ah          ;length in AX
  190.         add     si, ax          ;point to end of symbol
  191.         cmp     [si], bp        ;check if symbol is past
  192.         jbe     _mcsym1         ;loop back if not
  193.         pop     ax              ;fix stack
  194.  
  195. _mcsym3 mov     si, bx          ;symbol source
  196.         inc     bx              ;check if FFFFH
  197.         jnz     _mcsym4         ;jump if not
  198.  
  199.         push    es                      ;start symbol segment
  200.         pop     ds                      ;
  201.         mov     si, OFFSET _mac_ssym    ;start symbol offset
  202.  
  203. ;--- copy symbol
  204.  
  205. _mcsym4 lodsb                   ;load length
  206.         mov     cl, al          ;
  207.         sub     ch, ch          ;CX gets length
  208.         rep
  209.         movsb                   ;copy symbol
  210.         sub     al, al
  211.         stosb                   ;store NUL
  212.  
  213.         sub     bp, dx          ;offset to symbol
  214.         mov     ax, bp          ;return it in AX
  215.  
  216.         pop     ds
  217.         pop     bp
  218.         pop     si
  219.         pop     di
  220.         clc
  221.         ret
  222.  
  223. ;--- address out of range
  224.  
  225. _mcsym5 pop     ds
  226.         pop     bp
  227.         pop     si
  228.         pop     di
  229.         stc
  230.         ret
  231.         ENDP
  232.  
  233. _macro2_end
  234.